import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class RedisDemo {
    private static void testGetSet(Jedis jedis){
        jedis.set("key1","Maybe");
        jedis.set("key2","chuxue");
        String value1=jedis.get("key1");
        String value2=jedis.get("key2");
        String value3=jedis.get("key3");

        System.out.println(value1+" "+value2);
        System.out.println(value3);
    }
    private static void testExistAndDel(Jedis jedis){
        jedis.set("key1","Maybe");
        jedis.set("key2","chuxue");
        jedis.set("key3","02");
        boolean key1 = jedis.exists("key1");
        System.out.println(key1);
        long key11 = jedis.del("key1");
        System.out.println(key11);
        boolean key12 = jedis.exists("key1");
        System.out.println(key12);
        key11=jedis.del("key2","key3");
        System.out.println(key11);
    }
    private static void testKeys(Jedis jedis){
        jedis.set("key1","Maybe");
        jedis.set("key2","chuxue");
        jedis.set("key3","02");
        //放入集合里面
        Set<String> keys=jedis.keys("*");
        System.out.println(keys);
        keys=jedis.keys("key?");
        System.out.println(keys);
    }
    private static void testExpireAndTTL(Jedis jedis){
//        long key1 = jedis.ttl("key1");
        jedis.setex("key1",60,"Maybe");
        long key1 =jedis.ttl("key1");
        System.out.println(key1);
    }
    private static void testType(Jedis jedis){
        jedis.set("key1","Maybe");
        System.out.println(jedis.type("key1"));
        jedis.lpush("key2","a","b","c");
        System.out.println(jedis.type("key2"));
        jedis.hset("key3","name","02");
        System.out.println(jedis.type("key3"));
        jedis.sadd("key4","111","222","333");
        System.out.println(jedis.type("key4"));
        jedis.zadd("key5",1,"chuxuexianding");
        System.out.println(jedis.type("key5"));
    }




    public static void main(String[] args) {
        JedisPool jedisPool=new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis=jedisPool.getResource()){
            String ping= jedis.ping();
//            System.out.println(ping);
//            testGetSet(jedis);
//            testExistAndDel(jedis);
//            testKeys(jedis);
//            testExpireAndTTL(jedis);
            testType(jedis);
        }
    }
}
